<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/5/20
 * Time: 14:33
 */

namespace api\controllers;


use common\controllers\ApiCommonCtrl;
use common\services\AreaSve;
use Yii;

class AreaController extends ApiCommonCtrl
{
    /**
     * 获取地区信息 BY:lihouse
     * @return array
     */
    public function actionInfo()
    {
        $request = Yii::$app->request;
        if ($request->isPost) {
            $areaId = $request->post('area_id');
            $rs = (new AreaSve())->getInfo(['area_id' => $areaId]);
            return $rs;
        }
    }


    /**
     * 获取地区列表 BY:lihouse
     * @return array
     */
    public function actionList()
    {
        $request = Yii::$app->request;
        if ($request->isPost) {
            $parentId = $request->post('area_parent_id', 0);
            $rs = (new AreaSve())->getList(['area_parent_id' => $parentId], 'area_id ASC');
            return $rs;
        }
    }


    /**
     * 获取当前用户城市列表 BY:lihouse
     * @return array
     */
    public function actionMyCityList()
    {
//        $this->checkLogin();
//        $Member = $this->TokenObj;
        $request = Yii::$app->request;
        $where = ['and'];
        array_push($where, ['=', 'area_deep', 2]);
        $areaName = $request->get('area_name');
        if ($areaName) {
            array_push($where, ['like', 'area_name', $areaName]);
        }
        $rs = (new AreaSve())->getList($where, 'area_sort DESC', true);
        return $rs;
//        if ($rs['code'] !== 0) {
//            return $rs;
//        }
//        //插入当前用户的城市地区ID
//        $rs['data']['member_city_area_id'] = $Member->city_id;
//        return $rs;

    }


    /**
     * H5地区JS文件
     */
    public function actionJs()
    {
        $AreaSve = new AreaSve();
        $list = $AreaSve->getAreaByLevel();
        echo 'var cityData3 = ' . $AreaSve->getJS($list);
    }
}